package com.infore.exchange.main.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.db.meta.MetaUtil;
import cn.hutool.db.meta.TableType;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.infore.common.constants.DataStatConstants;
import com.infore.common.exception.MyException;
import com.infore.common.model.dto.KeyValueVo;
import com.infore.common.model.dto.TreeDto;
import com.infore.common.model.dto.exchange.TableIndexDto;
import com.infore.common.model.entity.exchange.TDatabaseInfo;
import com.infore.common.response.ApiResponse;
import com.infore.common.utils.EncryptAESUtil;
import com.infore.common.utils.NumberUtil;
import com.infore.common.utils.StringUtils;
import com.infore.exchange.main.dao.TDatabaseInfoMapper;
import com.infore.exchange.main.service.TDatabaseInfoService;
import com.infore.exchange.main.utils.SqlUtils;
import com.infore.metadata.core.enums.DatabaseEnum;
import com.infore.metadata.core.model.ColumnModel;
import com.infore.metadata.core.model.MetadataConfig;
import com.infore.metadata.core.model.SimpleDataSource;
import com.infore.metadata.core.model.TableModel;
import com.infore.metadata.core.service.MetadataQueryHandle;
import com.infore.screw.core.exception.QueryException;
import com.infore.screw.core.metadata.Table;
import com.infore.screw.core.query.DatabaseQuery;
import com.infore.screw.core.query.DatabaseQueryFactory;
import com.infore.screw.core.query.dm.model.DmTableModel;
import com.infore.screw.core.query.mysql.model.MySqlTableModel;
import com.infore.screw.core.query.oracle.model.OracleTableModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 数据库信息表 服务实现类
 * </p>
 *
 * @author lijh
 * @since 2023-02-07
 */
@Service
@Slf4j
public class TDatabaseInfoServiceImpl extends ServiceImpl<TDatabaseInfoMapper, TDatabaseInfo> implements TDatabaseInfoService {

    @Value("${spring.datasource.druid.dataExchange.driver-alias}")
    private String driverAlias;
    @Autowired
    private TDatabaseInfoMapper databaseInfoMapper;

    @Override
    public boolean checkDatabaseConnect(TDatabaseInfo TDatabaseInfo) {
        boolean ok = false;
        SimpleDataSource simpleDataSource = getDatabaseConnect(TDatabaseInfo);
        if(simpleDataSource!=null){
            ok =  true;
        }
        try {
            if(simpleDataSource!=null){
                simpleDataSource.closeConnection();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ok;
    }

    @Override
    public SimpleDataSource getDatabaseConnect(TDatabaseInfo tDatabaseInfo){
        if(tDatabaseInfo == null){
            throw new MyException("500","数据源为空", JSONUtil.toJsonStr(tDatabaseInfo));
        }
        String dePassword = null;
        try {
            dePassword = EncryptAESUtil.aesDecrypt(tDatabaseInfo.getUserPassword(), DataStatConstants.AES_KEY_PASSWORD);
        } catch (Exception e) {
            throw new MyException("500",tDatabaseInfo.getDatabaseName()+"密码解密失败");
        }
        SimpleDataSource simpleDataSource =null;
        DatabaseEnum databaseEnum = null;
        String jdbcUrl = null;
        String template=null;
        if("ORACLE".equals(tDatabaseInfo.getDatabaseType().toUpperCase())){
            databaseEnum = DatabaseEnum.ORACLE;
            template = "jdbc:oracle:thin:@{}:{}:{}";
            jdbcUrl = StrUtil.format(template,tDatabaseInfo.getDatabaseIp(),tDatabaseInfo.getDatabasePort(),tDatabaseInfo.getDatabaseInstanceName());
        }else if("MYSQL".equals(tDatabaseInfo.getDatabaseType().toUpperCase())){
            databaseEnum = DatabaseEnum.MYSQL;
            template = "jdbc:mysql://{}:{}/{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&useInformationSchema=true";
            jdbcUrl = StrUtil.format(template,tDatabaseInfo.getDatabaseIp(),tDatabaseInfo.getDatabasePort(),tDatabaseInfo.getDatabaseInstanceName());
        }else if("DM".equals(tDatabaseInfo.getDatabaseType().toUpperCase())){
            databaseEnum = DatabaseEnum.DM;
            template = "jdbc:dm://{}:{}?schema={}";
            jdbcUrl = StrUtil.format(template,tDatabaseInfo.getDatabaseIp(),tDatabaseInfo.getDatabasePort(),tDatabaseInfo.getDatabaseInstanceName());
        } else{
            throw new MyException("500",tDatabaseInfo.getDatabaseType()+"数据库类型不存在");
        }
        try {
            simpleDataSource = new SimpleDataSource(databaseEnum,
                    jdbcUrl,
                    tDatabaseInfo.getUserName(),
                    dePassword
            );
        } catch (Exception e) {
            e.printStackTrace();
            throw new MyException("500",tDatabaseInfo.getDatabaseInstanceName()+"数据库连接异常",e.getMessage());
        }
        return simpleDataSource;
    }


    @Override
    public List<TreeDto> getDatasourcesGroupByDatabaseType(String tableName){
        List<TreeDto> result = new ArrayList<>();
        Wrapper<TDatabaseInfo> wrapper = new EntityWrapper<TDatabaseInfo>();
        List<TDatabaseInfo> list = this.selectList(wrapper);
        Map<String, List<TDatabaseInfo>> group = list.stream().collect(Collectors.groupingBy(g -> g.getDatabaseType()));
        for(Map.Entry<String,List<TDatabaseInfo>>  entry : group.entrySet()){
            String key = entry.getKey();
            List<TDatabaseInfo> value = entry.getValue();
            TreeDto tree = new TreeDto();
            tree.setLabel(key);
            tree.setRemark(key);
            tree.setId(key);
            List<TreeDto> childs = new ArrayList<>();
            for (TDatabaseInfo datasource:value) {
                TreeDto child = new TreeDto();
                child.setId(datasource.getDatabaseId());
                child.setCode(datasource.getDatabaseId());
                child.setLabel(datasource.getDatabaseName());
                child.setChildren(getTables(datasource,tableName));
                child.setRemark(datasource.getDatabaseName());
                childs.add(child);
            }
            tree.setChildren(childs);
            result.add(tree);
        }
        return result;
    }
    @Override
    public List<TreeDto> getDatasourcesAllTableInfo(String tableName){
        List<TreeDto> result = new ArrayList<>();
        Wrapper<TDatabaseInfo> wrapper = new EntityWrapper<TDatabaseInfo>();
        List<TDatabaseInfo> list = this.selectList(wrapper);
        Map<String, List<TDatabaseInfo>> group = list.stream().collect(Collectors.groupingBy(g -> g.getDatabaseType()));
        for(Map.Entry<String,List<TDatabaseInfo>>  entry : group.entrySet()){
            String key = entry.getKey();
            List<TDatabaseInfo> value = entry.getValue();
            TreeDto tree = new TreeDto();
            tree.setLabel(key);
            List<TreeDto> childs = new ArrayList<>();
            for (TDatabaseInfo datasource:value) {
                TreeDto child = new TreeDto();
                child.setId(datasource.getDatabaseId());
                child.setCode(datasource.getDatabaseId());
                child.setLabel(datasource.getDatabaseName());
                child.setRemark(datasource.getDatabaseInstanceName());
                child.setChildren(getTablesAndColumns(datasource,tableName));
                childs.add(child);
            }
            tree.setChildren(childs);
            result.add(tree);
        }
        return result;
    }

    @Override
    public List<ColumnModel> getTablesColumns(String databaseId, String tableName) {
        TDatabaseInfo schema = this.selectById(databaseId);
        SimpleDataSource simpleDataSource = getDatabaseConnect(schema);
        List<ColumnModel> columnModel = null;
        // 非必要，按需配置
        MetadataConfig metadataConfig = new MetadataConfig();
        //匹配过滤查询的ORACLE用户，不指定用户会查询整个库的数据
        if("ORACLE".equals(schema.getDatabaseType().toUpperCase())){
            metadataConfig.setSchemaPattern("%"+schema.getUserName()+"%");
        }
        //匹配过滤查询的DM库，不指定用户会查询整个库的数据
        if("DM".equals(schema.getDatabaseType().toUpperCase())){
            metadataConfig.setSchemaPattern(schema.getDatabaseInstanceName());
        }
        //匹配过滤查的表名
        metadataConfig.setTableNamePattern(tableName);
        MetadataQueryHandle metadataQueryHandle = new MetadataQueryHandle();
        try {
            List<TableModel> tableModels = metadataQueryHandle.queryTablesColumnsCoreHandle(simpleDataSource, metadataConfig);
            if(tableModels!=null){
                columnModel = tableModels.get(0).getColumnModelList();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                if(simpleDataSource!=null){
                    simpleDataSource.closeConnection();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return columnModel;
    }

    /**
    * @Deacription 获取表的自增列
    * @MethodName getTablesIncreColumns
    * @param databaseId
    * @param tableName
    * @return {@link List< Map< String, String>>}
    * @Author lijianhua
    * @Date 2023/3/1 9:45
    **/
    @Override
    public List<Map<String, String>> getTablesIncreColumns(String databaseId,String tableName){
        List<Map<String, String>> returnList = new ArrayList<>();
        List<ColumnModel> list = getTablesColumns(databaseId, tableName);
        for (ColumnModel cm:list) {
            boolean ok = false;
            String increType="";
            String type = cm.getType();
            if(type.equalsIgnoreCase("NUMBER") || type.equalsIgnoreCase("LONG")
                    ||type.equalsIgnoreCase("INT")||type.equalsIgnoreCase("BIG INT") ){
                ok = true;
                increType ="long";

            }else  if(type.equalsIgnoreCase("DATE") || type.equalsIgnoreCase("TIMESTAMPL")
                    || type.equalsIgnoreCase("DATETIME")){
                ok = true;
                increType="time";
            }
            if(ok){
                Map<String, String> map =  new HashMap<>();
                map.put("increType",increType);
                map.put("columName",cm.getColumnName());
                returnList.add(map);
            }

        }
        return returnList;
    }

    /**
    * @Deacription 表索引
    * @MethodName getTablesIndex
    * @param databaseId
     * @param tableName
    * @return {@link List< Map< String, Object>>}
    * @Author lijianhua
    * @Date 2023/2/28 10:58
    **/

    @Override
    public List<TableIndexDto> getTablesIndexs(String databaseId, String tableName) {

        TDatabaseInfo schema = this.selectById(databaseId);
        SimpleDataSource dataSource = getDatabaseConnect(schema);
        List<Map<String, Object>> list=null;

        List<TableIndexDto> returnList = new ArrayList<>();
        if("MYSQL".equalsIgnoreCase(schema.getDatabaseType())){
            list = SqlUtils.getIndex(dataSource, schema.getDatabaseInstanceName(), null, tableName);

        }else if("ORACLE".equalsIgnoreCase(schema.getDatabaseType())){
            list = SqlUtils.getIndex(dataSource,null,schema.getUserName(),tableName);
        }else if("DM".equalsIgnoreCase(schema.getDatabaseType())){
            list = SqlUtils.getIndex(dataSource,null,schema.getDatabaseInstanceName(),tableName);
        }
        for (Map<String, Object> index:list) {
            TableIndexDto dto = new TableIndexDto();
            dto.setTableName(index.get("TABLE_NAME").toString());
            dto.setIndexName(index.get("INDEX_NAME").toString());
            dto.setColumnName(index.get("COLUMN_NAME").toString());
            dto.setUnique(index.get("NON_UNIQUE").toString()=="1"? "0":"1");
            returnList.add(dto);
        }

        return returnList;
    }
    /**
    * @Deacription 获取表的信息
    * @MethodName getTableInfoByDatabaseId
    * @param databaseId
    * @return {@link List<? extends  Table>}
    * @Author lijianhua
    * @Date 2023/2/21 16:57
    **/
    @Override
    public List< Map<String,Object>>   getTableInfoByDatabaseId(String databaseId,String tableName){
        TDatabaseInfo schema = this.selectById(databaseId);
        SimpleDataSource dataSource = getDatabaseConnect(schema);
        //screw-core 1.5.0版本只支持HikariDataSource驱动，现已本地升级
//        DataSource dataSource = SqlUtils.getDataSourceByDatabaseInfo(schema,null, DataSourceType.DRUID.getType());
        //获取query对象
        List< Map<String,Object>>  returnList = null;
        try {
            DatabaseQuery query = new DatabaseQueryFactory(dataSource).newInstance();
            returnList = new ArrayList<>();
            if("MYSQL".equalsIgnoreCase(schema.getDatabaseType())){

                StringBuilder  sqlBuld =new StringBuilder("SELECT table_name,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') as  CREATE_TIME,DATE_FORMAT(update_time,'%Y-%m-%d %H:%i:%s') as UPDATE_TIME FROM information_schema.TABLES\n" +
                        "WHERE TABLE_TYPE='BASE TABLE' and  table_schema = '{}' ")  ;
                if(StringUtils.isNotEmpty(tableName)){
                    sqlBuld.append(" AND table_name='{}'");
                }
                String sql = StrUtil.format(sqlBuld.toString(),schema.getDatabaseInstanceName(),tableName);
                List<Map<String, Object>> list = SqlUtils.executeQuerySql(getDatabaseConnect(schema),sql);
                if(list==null){
                    return null;
                }
                List<MySqlTableModel> tables = (List<MySqlTableModel>)query.getTables();
                Map<String, List<MySqlTableModel>> tableInfo = tables.stream().collect(Collectors.groupingBy(g -> g.getTableName()));
                for (Map<String, Object> table:list ) {
                    Map<String,Object> tableMap = new HashMap<>();
                    MySqlTableModel tableModel = tableInfo.get(table.get("TABLE_NAME")).get(0);
                    tableMap.put("tableName",table.get("TABLE_NAME"));
                    tableMap.put("remarks",tableModel.getRemarks());
                    tableMap.put("tableSchem",tableModel.getTableSchem());
                    tableMap.put("createTime",table.get("CREATE_TIME"));
                    tableMap.put("updateTime",table.get("UPDATE_TIME"));
                    returnList.add(tableMap);
                }
            }else if("ORACLE".equalsIgnoreCase(schema.getDatabaseType())){

/*                //oracle 需要授权才能访问 dba_objects表
                StringBuilder  sqlBuld =new StringBuilder( " select OBJECT_NAME  as TABLE_NAME,TO_CHAR(CREATED,'yyyy-mm-dd hh24:mi:ss')  as CREATE_TIME," +
                        "TO_CHAR(LAST_DDL_TIME,'yyyy-mm-dd hh24:mi:ss') as UPDATE_TIME from dba_objects where OWNER='{}'")  ;
                if(StringUtils.isNotEmpty(tableName)){
                    sqlBuld.append(" AND object_name='{}'");
                }
                String sql = StrUtil.format(sqlBuld.toString(),schema.getUserName(),tableName);
                List<Map<String, Object>> list = SqlUtils.executeQuerySql(getDatabaseConnect(schema),sql);
                if(list==null){
                    return null;
                }
                */
                List<OracleTableModel> tables = (List<OracleTableModel>)query.getTables();
                for (OracleTableModel table:tables ) {
                    Map<String,Object> tableMap = new HashMap<>();
                    tableMap.put("tableName",table.getTableName());
                    tableMap.put("remarks",table.getRemarks());
                    tableMap.put("tableSchem",table.getTableSchem());
                    tableMap.put("createTime","");
                    tableMap.put("updateTime","");
                    returnList.add(tableMap);
                }
            }else if("DM".equalsIgnoreCase(schema.getDatabaseType())){
                List<DmTableModel> tables = (List<DmTableModel>)query.getTables();
                for (DmTableModel table:tables ) {
                    Map<String,Object> tableMap = new HashMap<>();
                    tableMap.put("tableName",table.getTableName());
                    tableMap.put("remarks",table.getRemarks());
                    tableMap.put("tableSchem",table.getTableSchem());
                    tableMap.put("createTime","");
                    tableMap.put("updateTime","");
                    returnList.add(tableMap);
                }

            }
        } catch (QueryException e) {
            e.printStackTrace();
        } finally {
            try {
                if(dataSource!=null){
                    dataSource.closeConnection();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }



    @Override
    public List<String> getTablesNameByDatabaseId(String databaseId){
        TDatabaseInfo schema = this.selectById(databaseId);
        SimpleDataSource simpleDataSource = getDatabaseConnect(schema);
        //用hutool工具类获取
        List<String> tablesList = null;
        try {
            tablesList = MetaUtil.getTables(simpleDataSource,
                    schema.getDatabaseType().equalsIgnoreCase("MYSQL")? schema.getDatabaseInstanceName():schema.getUserName(),
                    TableType.TABLE);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(simpleDataSource!=null){
                    simpleDataSource.closeConnection();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return tablesList;
    }

    public List<TreeDto> getTables(TDatabaseInfo schema,String tableName) {
        List<TreeDto> result = new ArrayList<>();
        SimpleDataSource simpleDataSource = getDatabaseConnect(schema);
        List<TableModel> tableModels = null;
        // 非必要，按需配置
        MetadataConfig metadataConfig = new MetadataConfig();
        //匹配过滤查询的ORACLE用户，不指定用户会查询整个库的数据
        if("ORACLE".equals(schema.getDatabaseType().toUpperCase())){
            metadataConfig.setSchemaPattern("%"+schema.getUserName()+"%");
        }
        //匹配过滤查询的DM库，不指定用户会查询整个库的数据
        if("DM".equals(schema.getDatabaseType().toUpperCase())){
            metadataConfig.setSchemaPattern(schema.getDatabaseInstanceName());
        }
        if(StringUtils.isNotEmpty(tableName)){
            //匹配过滤查的表名
            metadataConfig.setTableNamePattern("%"+tableName+"%");
        }
        MetadataQueryHandle metadataQueryHandle = new MetadataQueryHandle();
        try {
            tableModels = metadataQueryHandle.queryTablesCoreHandle(simpleDataSource, metadataConfig);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                if(simpleDataSource!=null){
                    simpleDataSource.closeConnection();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        for (TableModel table:tableModels) {

            String remarks = table.getRemarks()==null? "":table.getRemarks();
            TreeDto tree = new TreeDto();
            tree.setId(table.getTableName());
            tree.setLabel(table.getTableName()+"（"+remarks+"）");
            tree.setCode(schema.getDatabaseId());
            tree.setRemark(remarks);
            result.add(tree);
        }
        return result;
    }


    public List<TreeDto> getTablesAndColumns(TDatabaseInfo schema,String tableName) {
        List<TreeDto> result = new ArrayList<>();

        SimpleDataSource simpleDataSource = getDatabaseConnect(schema);
        List<TableModel> tableModels = null;
        // 非必要，按需配置
        MetadataConfig metadataConfig = new MetadataConfig();
        //匹配过滤查询的ORACLE用户，不指定用户会查询整个库的数据
        if("ORACLE".equals(schema.getDatabaseType().toUpperCase())){
            metadataConfig.setSchemaPattern("%"+schema.getUserName()+"%");
        }
        //匹配过滤查询的DM库，不指定用户会查询整个库的数据
        if("DM".equals(schema.getDatabaseType().toUpperCase())){
            metadataConfig.setSchemaPattern(schema.getDatabaseInstanceName());
        }

        if(StringUtils.isNotEmpty(tableName)){
            //匹配过滤查的表名
            metadataConfig.setTableNamePattern("%"+tableName+"%");
        }
        MetadataQueryHandle metadataQueryHandle = new MetadataQueryHandle();
        try {
            tableModels = metadataQueryHandle.queryTablesColumnsCoreHandle(simpleDataSource, metadataConfig);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                if(simpleDataSource!=null){
                    simpleDataSource.closeConnection();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        for (TableModel table:tableModels) {
            TreeDto tree = new TreeDto();
            tree.setLabel(table.getTableName());
            tree.setCode(schema.getDatabaseId());
            tree.setRemark(table.getRemarks());

            List<TreeDto> childs = new ArrayList<>();
            List<ColumnModel> columnModelList = table.getColumnModelList();
            for (ColumnModel col:columnModelList) {
                TreeDto child = new TreeDto();
                child.setLabel(col.getColumnName());
                child.setRemark(col.getRemarks());
                childs.add(child);
            }
            tree.setChildren(childs);
            result.add(tree);
        }
        return result;
    }


    /**
    * @Deacription 基础库记录行数和占用磁盘空间大小
    * @MethodName getDatabaseRowNumAndTotalSpace
    * @param
    * @return {@link Map< String, Object>}
    * @Author lijianhua
    * @Date 2023/2/23 13:43
    **/
    @Override
    public Map<String, Object> getDatabaseRowNumAndTotalSpace() {

        Map<String, Object> returnMap = new HashMap<>();
        KeyValueVo rows = new KeyValueVo();
        KeyValueVo space = new KeyValueVo();
        Map<String, Object> map = databaseInfoMapper.queryDatabaseRowNumAndTotalSpace(driverAlias,"db_envdatacenter");
        if(map==null){
            throw new MyException("500","db_envdatacenter数据库不存在");
        }
        Long totalRows = Long.valueOf(map.get("totalRows")==null? "0": map.get("totalRows").toString());
        Map<String, Object> valUnit = NumberUtil.getValUnit(totalRows);

        double totalGB = Double.parseDouble(map.get("totalGB").toString());
        rows.setKey("totalRows");
        rows.setValue(valUnit.get("val"));
        rows.setUnit(valUnit.get("unit")==null? "条":valUnit.get("unit").toString()+"条");
        space.setKey("totalSpace");
        space.setValue(totalGB);
        space.setUnit("GB");
        returnMap.put("rows",rows);
        returnMap.put("space",space);
        return returnMap;
    }

    /**
    * @Deacription 数据服务有多少数据库和多少数据表
    * @MethodName getSchematabes
    * @param
    * @return {@link Map< String, Object>}
    * @Author lijianhua
    * @Date 2023/2/23 14:55
    **/
    @Override
    public Map<String, Integer> getSchematabes() {
        Map<String,Integer> map = new HashMap<>();
        List<Map<String, Object>> list = databaseInfoMapper.querySchematabes(driverAlias);
        int tabes = list.stream().mapToInt(m -> Integer.parseInt(m.get("schema_tabes").toString())).sum();
        map.put("schemas",list.size());
        map.put("tabes",tabes);
        return map;
    }

    /**
    * @Deacription 修改表注释
    * @MethodName updateTableComment
    * @param databaseId
    * @param tableName
    * @param comment
    * @return {@link ApiResponse}
    * @Author lijianhua
    * @Date 2023/3/16 14:54
    **/
    @Override
    public ApiResponse updateTableComment(String databaseId, String tableName, String comment) {
        boolean ok = false;
        TDatabaseInfo schema = this.selectById(databaseId);
        SimpleDataSource dataSource = getDatabaseConnect(schema);
        if("MYSQL".equalsIgnoreCase(schema.getDatabaseType())){
            String sql = StrUtil.format("alter table {} comment '{}' ",tableName,comment) ;
            ok= SqlUtils.executeSql(dataSource, sql);
        }else if("ORACLE".equalsIgnoreCase(schema.getDatabaseType()) || "DM".equalsIgnoreCase(schema.getDatabaseType())){
            String sql =StrUtil.format( "comment on table {} is '{}' ",tableName,comment);
            ok= SqlUtils.executeSql(dataSource,sql);
        }
        if(ok){
            return ApiResponse.ok();
        }
        return ApiResponse.error("500","表备注修改失败");
    }
}
